<?php


namespace Singleton;


class Client
{
    public static function main()
    {
        $singleton1 = Singleton::getInstance();
        $singleton2 = Singleton::getInstance();

        var_dump($singleton1, $singleton2, $singleton1 === $singleton2);

        $singleton1->id = 1;
        var_dump($singleton1, $singleton2, $singleton1 === $singleton2);
    }
}


class Singleton
{
    protected static Singleton $instance;

    private function __construct()
    {
    }

    private function __clone()
    {
    }

    /**
     * @return Singleton
     */
    public static function getInstance(): Singleton
    {
        if (!isset(self::$instance)) {
            self::$instance = new self();
        }
        return self::$instance;
    }
}


Client::main();
